"""Video Add Column duration

Revision ID: 611f731424bc
Revises: c6bb7183eb1a
Create Date: 2025-05-30 11:42:33.674823

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import sqlite

# revision identifiers, used by Alembic.
revision: str = '611f731424bc'
down_revision: Union[str, None] = 'c6bb7183eb1a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_file_uploads_id'), table_name='file_uploads')
    op.drop_table('file_uploads')
    op.drop_index(op.f('ix_hot_videos_id'), table_name='hot_videos')
    op.drop_table('hot_videos')
    op.drop_table('_videos_old_20250515')
    op.drop_table('system_settings')
    op.drop_table('scheduler_tasks')
    op.drop_column('monitored_users', 'sequence_number')
    op.add_column('videos', sa.Column('duration', sa.Integer(), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('videos', 'duration')
    op.add_column('monitored_users', sa.Column('sequence_number', sa.VARCHAR(length=50), nullable=True))
    op.create_table('scheduler_tasks',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('task_id', sa.VARCHAR(), nullable=False),
    sa.Column('task_name', sa.VARCHAR(), nullable=False),
    sa.Column('status', sa.VARCHAR(), nullable=True),
    sa.Column('last_run_at', sa.DATETIME(), nullable=True),
    sa.Column('next_run_at', sa.DATETIME(), nullable=True),
    sa.Column('last_result', sa.VARCHAR(), nullable=True),
    sa.Column('created_at', sa.DATETIME(), nullable=True),
    sa.Column('updated_at', sa.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('task_id')
    )
    op.create_table('system_settings',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('key', sa.VARCHAR(), nullable=False),
    sa.Column('value', sa.VARCHAR(), nullable=True),
    sa.Column('description', sa.VARCHAR(), nullable=True),
    sa.Column('updated_at', sa.DATETIME(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('key')
    )
    op.create_table('_videos_old_20250515',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('user_id', sa.INTEGER(), nullable=True),
    sa.Column('platform', sa.VARCHAR(), nullable=False),
    sa.Column('video_id', sa.VARCHAR(), nullable=False),
    sa.Column('title', sa.TEXT(), nullable=True),
    sa.Column('download_url', sa.TEXT(), nullable=True),
    sa.Column('local_path', sa.VARCHAR(), nullable=True),
    sa.Column('download_status', sa.VARCHAR(), nullable=True),
    sa.Column('last_download_url', sa.VARCHAR(), nullable=True),
    sa.Column('created_at', sa.DATETIME(), nullable=True),
    sa.Column('download_at', sa.DATETIME(), nullable=True),
    sa.Column('retry_count', sa.INTEGER(), nullable=True),
    sa.Column('next_retry_at', sa.DATETIME(), nullable=True),
    sa.Column('is_category', sa.BOOLEAN(), nullable=True),
    sa.Column('is_translate', sa.BOOLEAN(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['monitored_users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('hot_videos',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('platform', sa.VARCHAR(), nullable=False),
    sa.Column('video_id', sa.VARCHAR(), nullable=False),
    sa.Column('title', sa.TEXT(), nullable=True),
    sa.Column('cover_url', sa.TEXT(), nullable=True),
    sa.Column('duration', sa.INTEGER(), nullable=True),
    sa.Column('author', sa.VARCHAR(), nullable=True),
    sa.Column('avatar_url', sa.TEXT(), nullable=True),
    sa.Column('fans_count', sa.INTEGER(), nullable=True),
    sa.Column('play_count', sa.INTEGER(), nullable=True),
    sa.Column('like_count', sa.INTEGER(), nullable=True),
    sa.Column('publish_time', sa.DATETIME(), nullable=True),
    sa.Column('video_url', sa.TEXT(), nullable=True),
    sa.Column('download_url', sa.TEXT(), nullable=True),
    sa.Column('download_status', sa.VARCHAR(), nullable=True),
    sa.Column('local_path', sa.VARCHAR(), nullable=True),
    sa.Column('rank', sa.INTEGER(), nullable=True),
    sa.Column('created_at', sa.DATETIME(), nullable=True),
    sa.Column('category', sa.VARCHAR(), nullable=True),
    sa.Column('is_favorite', sa.BOOLEAN(), nullable=True),
    sa.Column('is_selected', sa.BOOLEAN(), nullable=True),
    sa.Column('is_category', sa.BOOLEAN(), nullable=True),
    sa.Column('is_translate', sa.BOOLEAN(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_hot_videos_id'), 'hot_videos', ['id'], unique=False)
    op.create_table('file_uploads',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('audio_path', sa.VARCHAR(), nullable=False),
    sa.Column('subtitle_path', sa.VARCHAR(), nullable=True),
    sa.Column('filename', sa.VARCHAR(), nullable=False),
    sa.Column('group_id', sa.TEXT(), nullable=True),
    sa.Column('order', sa.INTEGER(), nullable=True),
    sa.Column('meta_data', sqlite.JSON(), nullable=True),
    sa.Column('created_at', sa.DATETIME(), nullable=True),
    sa.Column('status', sa.VARCHAR(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_file_uploads_id'), 'file_uploads', ['id'], unique=False)
    # ### end Alembic commands ###
